home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE2 / PD / VINCE / !ViNCe / c / hextile16 < prev    next >
Text File  |  2002-03-10  |  3KB  |  131 lines

  1. /*
  2.  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
  3.  *
  4.  *  This is free software; you can redistribute it and/or modify
  5.  *  it under the terms of the GNU General Public License as published by
  6.  *  the Free Software Foundation; either version 2 of the License, or
  7.  *  (at your option) any later version.
  8.  *
  9.  *  This software is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU General Public License
  15.  *  along with this software; if not, write to the Free Software
  16.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  17.  *  USA.
  18.  */
  19.  
  20. /*
  21.  * hextile.c - handle hextile encoding.
  22.  *
  23.  * This file shouldn't be compiled directly.  It is included multiple times by
  24.  * rfbproto.c, each time with a different definition of the macro BPP.  For
  25.  * each value of BPP, this file defines a function which handles a hextile
  26.  * encoded rectangle with BPP bits per pixel.
  27.  */
  28.  
  29. static bppinfo[4096];
  30.  
  31. static Bool HandleHextile16 (int rx, int ry, int rw, int rh)
  32. {
  33.   CARD16 bg, fg;
  34.   int i;
  35.   CARD8 *ptr;
  36.   int x, y, w, h;
  37.   int sx, sy, sw, sh;
  38.   CARD8 subencoding;
  39.   CARD8 nSubrects;
  40.  
  41.   for (y = ry; y < ry+rh; y += 16) {
  42.     for (x = rx; x < rx+rw; x += 16) {
  43.       w = h = 16;
  44.       if (rx+rw - x < 16)
  45.     w = rx+rw - x;
  46.       if (ry+rh - y < 16)
  47.     h = ry+rh - y;
  48.  
  49.       if (!ReadFromRFBServer((char *)&subencoding, 1))
  50.     return False;
  51.  
  52.       if (subencoding & rfbHextileRaw) {
  53.         int dithered;
  54.         dithered = 0;
  55.         if (subencoding & rfbHextileRawDither) {
  56.           dithered = 1;
  57.         }
  58.  
  59.         if (dithered) {
  60.         if (!ReadFromRFBServer(buffer, w * h))
  61.         return False;
  62.           display_raw(x, y, w, h, buffer, 1);
  63.  
  64.         } else {
  65.         if (!ReadFromRFBServer(buffer, w * h * (BPP / 8)))
  66.         return False;
  67.           display_raw(x, y, w, h, buffer, 0);
  68.         }
  69.     continue;
  70.       }
  71.  
  72.       if (subencoding & rfbHextileBackgroundSpecified) {
  73.     if (!ReadFromRFBServer((char *)&bg, sizeof(bg)))
  74.       return False;
  75.       }
  76.  
  77.       display_fillrectangle(x, y, w, h, bg);
  78.  
  79.       if (subencoding & rfbHextileForegroundSpecified) {
  80.     if (!ReadFromRFBServer((char *)&fg, sizeof(fg)))
  81.       return False;
  82.       }
  83.  
  84.       if (!(subencoding & rfbHextileAnySubrects)) {
  85.     continue;
  86.       }
  87.  
  88.       if (!ReadFromRFBServer((char *)&nSubrects, 1))
  89.     return False;
  90.  
  91.       ptr = (CARD8 *)buffer;
  92.  
  93.       if (subencoding & rfbHextileSubrectsColoured) {
  94.     if (!ReadFromRFBServer(buffer, nSubrects * (2 + (BPP / 8))))
  95.       return False;
  96.         subrect += nSubrects;
  97.  
  98.     for (i = 0; i < nSubrects; i++) {
  99.       fg = ptr[0] | (ptr[1]<<8);
  100.       ptr += 2;
  101.       sx = rfbHextileExtractX(*ptr);
  102.       sy = rfbHextileExtractY(*ptr);
  103.       ptr++;
  104.       sw = rfbHextileExtractW(*ptr);
  105.       sh = rfbHextileExtractH(*ptr);
  106.       ptr++;
  107.           display_fillrectangle(x+sx, y+sy, sw, sh, fg);
  108.     }
  109.  
  110.       } else {
  111.     if (!ReadFromRFBServer(buffer, nSubrects * 2))
  112.       return False;
  113.         subrect += nSubrects;
  114.  
  115.     for (i = 0; i < nSubrects; i++) {
  116.       sx = rfbHextileExtractX(*ptr);
  117.       sy = rfbHextileExtractY(*ptr);
  118.       ptr++;
  119.       sw = rfbHextileExtractW(*ptr);
  120.       sh = rfbHextileExtractH(*ptr);
  121.       ptr++;
  122.  
  123.           display_fillrectangle(x+sx, y+sy, sw, sh, fg);
  124.     }
  125.       }
  126.     }
  127.   }
  128.  
  129.   return True;
  130. }
  131.